status-bar (scrapbox)に情報を表示するUserScript
code:script.js
export function setup(init) {
const statusBar = getStatusBar();
const item = createItem();
// initialization
switch (typeof init) {
case 'string':
case 'number':
item.textContent = init;
break;
case 'object':
if (!(init instanceof HTMLElement)) break;
item.append(init);
break;
default:
break;
}
statusBar.append(item);
return {
render: (child) => {
item.textContent = '';
item.append(child);
},
dispose: () => item.remove(),
};
}
function createItem() {
const item = document.createElement('div');
item.dataset.id = item-${Math.random()};
return item;
}
function getStatusBar() {
return document.getElementsByClassName('status-bar')?.0; }
読み込み中を表すspinnerはこれ
code:script.js
export function createSpinner() {
const span = document.createElement('span');
span.classList.add('item');
span.insertAdjacentHTML('beforeend',<i class="fa fa-spinner"></i>);
return span;
}
test code
code:js
import('/api/code/takker/status-bar_(scrapbox)に情報を表示するUserScript/test.js');
code:test.js
import {setup} from './script.js';
window.setup = setup;
お遊び
code:js
import('/api/code/takker/status-bar_(scrapbox)に情報を表示するUserScript/test2.js');
code:test2.js
import {setup, createSpinner} from './script.js';
for (let i = 0; i < 20; i++) {
const {render} = setup();
render(createSpinner());
}